const express = require("express");
const router = express.Router();
const { Category } = require("../models");
const { success, failure } = require("../utils/responses");

/**
 * 获取所有分类
 * GET /categories
 */
router.get("/", async (req, res) => {
  try {
    const categories = await Category.findAll({
      order: [
        ["rank", "ASC"],
        ["id", "DESC"],
      ],
    });
    success(res, "获取分类成功", categories);
  } catch (error) {
    failure(res, error);
  }
});

module.exports = router;
